package com.prs.crm.dao.person.impl;

import java.util.Collection;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.dao.person.DossierDao;
import com.prs.crm.domain.person.Department;
import com.prs.crm.domain.person.Dossier;

public class DossierDaoImpl extends BaseDaoImpl<Dossier> implements DossierDao{

	@SuppressWarnings("unchecked")
	@Override
	public Collection<Dossier> findByDepartment(final Department department) {
		Criteria criteria=this.getSession().createCriteria(Dossier.class);
		criteria.add(Restrictions.eq("department", department));
		criteria.addOrder(Order.asc("id"));
		return criteria.list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Dossier> getAllDossier() {
		Criteria criteria=this.getSession().createCriteria(Dossier.class);
		return criteria.list();
	}

	@Override
	public Dossier getDossierById(Integer id) {
		Criteria criteria=this.getSession().createCriteria(Dossier.class)
		.add(Restrictions.eq("id", id));
		return (Dossier) criteria.list().get(0);
	}

}
